package com.zhanqiao.controller;





import com.google.gson.Gson;
import com.zhanqiao.domain.MessageBean;
import com.zhanqiao.service.MessageService;
import com.zhanqiao.service.MessagesService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MessageController extends HttpServlet{
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
      resp.setContentType("application/json;charset=utf-8");
      req.setCharacterEncoding("utf8");
        String page = req.getParameter("page");
        String limit = req.getParameter("limit");

        try {
            MessageService messageService=new MessagesService();
            List<MessageBean> list = messageService.messageService(page,limit);
            Map hashMap = new HashMap();
            hashMap.put("code","0");
            hashMap.put("msg","");
            hashMap.put("count","1000");
            hashMap.put("data",list);
            System.out.println(list);
            String jsonString= new Gson().toJson(hashMap);
            System.out.println(jsonString);
            resp.getWriter().write(jsonString);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
